package com.mb.common.service.impl;

import com.mb.common.service.NotifysService;
import com.mb.oa.domain.NotifyDO;
import com.mb.oa.service.NotifyService;
import com.mb.system.domain.UserDO;
import com.mb.system.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("notifyService")
@Slf4j
public class NotifysServiceImpl implements NotifysService {

    @Autowired
    private SimpMessagingTemplate template;

    @Autowired
    UserService userService;

    @Autowired
    private NotifyService notifyService;

    @Override
    public void sendNotify(Map<String,Object> msgMap) {
        //给在线用户发送通知
        NotifyDO notifyDO = new NotifyDO();
        Long[] userIds = new Long[5];
        // 发送给超级管理员
        userIds[0] = (long)1;
        notifyDO.setUserIds(userIds);
        notifyDO.setTitle((String) msgMap.get("name"));
        notifyDO.setContent((String)msgMap.get("phone"));
        notifyDO.setType("1");
        notifyDO.setCreateBy(1L);
        notifyDO.setStatus("1");
        notifyDO.setRemarks((String) msgMap.get("name"));
        notifyService.save(notifyDO);

//        log.info("sendNotify run ::"+msgMap.get("msg"));
//
//        // 发送给超级管理员
//        String name = "admin";
//        UserDO userDO = userService.getByName(name);
//        log.info("userDo userName::"+userDO.toString());
//        template.convertAndSendToUser(userDO.toString(), "/queue/notifications", msgMap.get("msg"));
//        template.convertAndSendToUser(userDO.toString(), "/queue/notifications", msgMap.get("msg"));
//        log.info("sendNotify::"+msgMap.get("msg"));
    }
}
